



//
//  NFilterView.m
//  nncloud
//
//  Created by macfai on 2018/11/13.
//  Copyright © 2018 youedata. All rights reserved.
//

#import "NFilterView.h"
#import "YearMonthPickerView.h"

@interface NFilterView()<STPickerSingleDelegate,YearMonthPickerViewDelegate>



@end

@implementation NFilterView

-(instancetype)init{
    self = [super init];
    if (self) {
//        [self setUI];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame{
    self=[super initWithFrame:frame];
    if (self) {
        self.frame = frame;
//        self.backgroundColor = [UIColor magentaColor];
        [self setUI];
    }
    return self;
}

- (void)setUI
{
    CGFloat viewHeight = 50.f;
//    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, ScreenHeight-50-64, ScreenWidth, viewHeight)];
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewHeight)];
    view.backgroundColor = [UIColor lightGrayColor];
    
    [self addSubview:view];
    UIButton *lbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    lbtn.frame = CGRectMake(0, 0.5, ScreenWidth/3, viewHeight);
    lbtn.backgroundColor = kBackgroundColor;
    lbtn.tag = 1001;
    [lbtn addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];
    lbtn.titleLabel.font = kFont15;
    [lbtn setTitle:@"时间：不限" forState:UIControlStateNormal];
    [lbtn setTitleColor:kGrayColor forState:UIControlStateNormal];
    self.leftBtn = lbtn;
    [view addSubview:lbtn];
    
    
    UIButton *mbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    mbtn.frame = CGRectMake(lbtn.right+0.5, 0.5, ScreenWidth/3, viewHeight);
    mbtn.tag = 1002;
    mbtn.backgroundColor = kBackgroundColor;
    mbtn.titleLabel.font = kFont15;
    [mbtn addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];
    [mbtn setTitle:@"类型：不限" forState:UIControlStateNormal];
    [mbtn setTitleColor:kGrayColor forState:UIControlStateNormal];
    self.midBtn = mbtn;
    [view addSubview:mbtn];
    
    
    UIButton *rbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    rbtn.frame = CGRectMake(mbtn.right+0.3, 0.5, ScreenWidth/3, viewHeight);
    rbtn.tag = 1003;
    rbtn.titleLabel.font = kFont15;
    rbtn.backgroundColor = kBackgroundColor;
    [rbtn addTarget:self action:@selector(tapAction:) forControlEvents:UIControlEventTouchUpInside];
    [rbtn setTitle:@"状态：不限" forState:UIControlStateNormal];
    [rbtn setTitleColor:kGrayColor forState:UIControlStateNormal];
    self.rightBtn = rbtn;
    [view addSubview:rbtn];
}

#pragma mark - 点击事件
- (void)tapAction:(UIButton *)btn
{
    
    YYLog(@"%ld",btn.tag);
    switch (btn.tag) {
        case 1001:
        {
            //时间选择
//            YearMonthPickerView *yearP = [[YearMonthPickerView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 216)];
//            yearP.delegate = self;
//            [yearP show];
            if (self.timeActionBolck) {
                self.timeActionBolck(btn);
            }
        }
            break;
            
        case 1002:
        {
            //类型选择
            NSMutableArray *data = [NSMutableArray arrayWithArray:@[@"咨询",@"投诉",@"建议",@"不限"]];
            STPickerSingle *single = [[STPickerSingle alloc]init];
            single.tag = 111;
            [single setArrayData:data];
            [single setTitle:@"问题类型"];
            [single setTitleUnit:@""];
            [single setDelegate:self];
            [single show];
        }
            break;
            
        case 1003:
        {
            //状态选择  0-10  @[@"待审核",@"等待受理",@"已受理",@"已转交相关部门",@"自行解答",@"等待用户确认",@"等待用户评价",@"已评价",@"已关闭",@"审核未通过",@"删除",]
            
            
            NSMutableArray *data;
            switch ([NUserModel shareInstance].index) {
                case 0:
                {
                     data = [NSMutableArray arrayWithArray:@[@"已受理",@"已转交相关部门",@"等待用户确认",@"不限",]];
                }
                    break;
                case 1:
                {
                     data = [NSMutableArray arrayWithArray:@[@"待审核",@"等待受理",@"不限",]];
                }
                    break;
                case 2:
                {
                     data = [NSMutableArray arrayWithArray:@[@"等待用户评价",@"已评价",@"已关闭",@"审核未通过",@"不限",]];
                }
                    break;
                    
                default:
                {
                     data = [NSMutableArray arrayWithArray:@[@"待审核",@"等待受理",@"已受理",@"已转交相关部门",@"自行解答",@"等待用户确认",@"等待用户评价",@"已评价",@"已关闭",@"审核未通过",@"删除",@"不限"]];
                }
                    
                    break;
            }
//            data = [NSMutableArray arrayWithArray:@[@"待审核",@"等待受理",@"已受理",@"已转交相关部门",@"自行解答",@"等待用户确认",@"等待用户评价",@"已评价",@"已关闭",@"审核未通过",@"删除",]];
            STPickerSingle *single = [[STPickerSingle alloc]init];
            single.tag = 222;
            [single setArrayData:data];
            [single setTitle:@"状态类型"];
            [single setTitleUnit:@""];
            [single setDelegate:self];
            [single show];
        }
            break;
            
        default:
            break;
    }
    
}

#pragma mark - yearmonthPicker
- (void)yearMonthPickerViewDidClickDone:(YearMonthPickerView *)yearMonthPickerView{
    
//    NSLog(@"%@***%@",yearMonthPickerView.selectedYear,yearMonthPickerView.selectedMonth);
//    if([self.delegate respondsToSelector:@selector(filterYearMonthPickerViewDidClickDone:)]){
//        [self.delegate filterYearMonthPickerViewDidClickDone:yearMonthPickerView];
//    }
    
}
#pragma mark - picker delegate
-(void)pickerSingle:(STPickerSingle *)pickerSingle selectedTitle:(NSString *)selectedTitle{
    YYLog(@"%@",selectedTitle);
    if([self.delegate respondsToSelector:@selector(filterPickerSingle:selectedTitle:)]){
        [self.delegate filterPickerSingle:pickerSingle selectedTitle:selectedTitle];
    }
}

- (void)pickerSingle:(STPickerSingle *)pickerSingle selectedTitle:(NSString *)selectedTitle selectIndex:(NSInteger)selectIndex{
    
    if ([self.delegate respondsToSelector:@selector(filterPickerSingle:selectedTitle:selectIndex:)]) {
        [self.delegate filterPickerSingle:pickerSingle selectedTitle:selectedTitle selectIndex:selectIndex];
    }
    
}


@end
